package com.blog.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author cgx
 * @Date 2021/8/15 10:30
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("创建时间自动注入");
        // 起始版本 3.3.0(推荐使用)
        this.strictInsertFill(metaObject, "createTime",Date.class, new Date());
        this.strictInsertFill(metaObject, "lookTime",Date.class, new Date());
        //权限自动注入，默认是普通人
//        log.info("赋予普通用户权限");
//        this.strictInsertFill(metaObject, "type",String.class,"1");

    }


    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("修改时间自动注入");
        // 起始版本 3.3.0(推荐)
        this.strictUpdateFill(metaObject, "updateTime",Date.class, new Date());
    }
}
